<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/6/7
 * Time: 15:20
 */
//控制器类
namespace Controller;



use Model\IndexModel;

class MemberController extends TooController{


    //订单管理
    public function order(){
        $model=new IndexModel();
        //查出所有的订单
        $order=$model->pdo_sel("select o.*,m.email from sh_order as o join sh_member as m on o.m_id = m.id  order by id desc",2);
        $this->view->assign("arr",$order);
        $this->view->display();
    }


    //订单操作
    public function order_upd(){
        $model=new IndexModel();
        $type=$_GET['type'];
        $id=$_GET['id'];
        if($type=='fh'){
            //发货操作
            $arr=array();
            $arr['wl_h']=$_GET['wl_h'];
            $arr['wl_n']=$_GET['wl_n'];
            $arr['stat']='4';
            if($model->pdo_upd("sh_order",$arr," where id = $id")){
                $this->retuAjax(array('type'=>2,'msg'=>'操作成功'));
            }else{
                $this->retuAjax(array('type'=>1,'msg'=>'操作失败'));
            }
        }
        else if($type==2){
            //付款
            if($model->pdo_upd("sh_order",array('stat'=>2,'pay'=>'后台付款')," where id = $id")){
                $this->retuAjax(array('type'=>2,'msg'=>'操作成功'));
            }else{
                $this->retuAjax(array('type'=>2,'msg'=>'操作失败'));
            }
        }else if($type=='5'){
            //收货
            if($model->pdo_upd("sh_order",array('stat'=>5)," where id = $id")){
                $this->retuAjax(array('type'=>2,'msg'=>'操作成功'));
            }else{
                $this->retuAjax(array('type'=>2,'msg'=>'操作失败'));
            }
        }else if($type==7){
            //退款
            $order=$model->pdo_sel("select * from sh_order where id = $id");
            if($model->pdo_upd("sh_order",array('stat'=>7)," where id = $id")){
                $member=$model->pdo_sel("select * from sh_member where id = {$order['m_id']}");
                //退还金钱
                $model->pdo_upd("sh_member",array('money'=>$member['money']+$order['money2'])," where id = {$member['id']}");

                $this->retuAjax(array('type'=>2,'msg'=>'操作成功'));
            }else{
                $this->retuAjax(array('type'=>2,'msg'=>'操作失败'));
            }
        }
    }
}